package nick.xbmc.utils
{
	public class Hash
	{
		public function Hash()
		{
		}
		
		private static function stringToAscii(someString:String):Array
		{
    		var arry = someString.split("");
   			
   			for(var i in arry)
   			{
        		arry[i] = arry[i].charCodeAt(0);
    		}
    
    		return arry;
		}

		
		public static function getFileName(file:String):String
		{
			file = file.toLowerCase();
			
			var mcrc:uint = 0xffffffff;
			
			var asciiArray:Array = stringToAscii(file);
			
			for (var x:Number = 0; x < asciiArray.length; x++)
			{						
				mcrc ^= asciiArray[x] << 24;
					
				for (var i:int = 0; i < 8; i++)
				{
					var temp:uint = mcrc & 0x80000000;
						
					if (temp == 0x80000000)
           			{
             				 mcrc = (mcrc << 1) ^ 0x04C11DB7;
           			}
           			else
          			{
              				mcrc <<= 1;
           			}
				}
			}
			
			var theHash:String = mcrc.toString(16);
			
			while (theHash.length < 8)
			{
				theHash = "0" + theHash;
			}
				
			return theHash;
		}
	}
}